//
//  LSZInformationPoorHouseholdsVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/10/29.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZInformationPoorHouseholdsVC.h"

@interface LSZInformationPoorHouseholdsVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewInformationPoorHouseholds;
@property(nonatomic,strong) NSArray * arrayName;
@end

@implementation LSZInformationPoorHouseholdsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"贫困户";
 
    [self.tableViewInformationPoorHouseholds registerClass:[LSZPoorInformationTableViewCell class] forCellReuseIdentifier:@"LSZPoorInformationTableViewCell"];
    [self.tableViewInformationPoorHouseholds  registerClass:[LSZBasicInformationPoorHeaderCell class] forHeaderFooterViewReuseIdentifier:@"LSZBasicInformationPoorHeaderCell"];
    self.arrayName = @[@"基本信息",@"家庭成员",@"帮扶措施",@"帮扶日志",@"帮扶责任人"];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 110;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LSZBasicInformationPoorHeaderCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZBasicInformationPoorHeaderCell"];
    cell.labelName.text = self.inquiryPoorHouseholdsMg.name;
    cell.labelNumber.text = self.inquiryPoorHouseholdsMg.personCount;
    NSMutableAttributedString *oneString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"致贫原因:%@",self.inquiryPoorHouseholdsMg.povertyReason]];
    NSMutableAttributedString *aString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"人均可支配收入:%@",self.inquiryPoorHouseholdsMg.averageIncome]];
    
    [oneString addAttribute:NSForegroundColorAttributeName value:titleColorLSZ range:NSMakeRange(5, self.inquiryPoorHouseholdsMg.povertyReason.length)];
    [aString addAttribute:NSForegroundColorAttributeName value:titleColorLSZ range:NSMakeRange(8, self.inquiryPoorHouseholdsMg.averageIncome.length)];
 
    cell.labelWhy.attributedText = oneString;
    cell.labelMoney.attributedText = aString;
    return cell;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZPoorInformationTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZPoorInformationTableViewCell" forIndexPath:indexPath];
    if (self.arrayName.count >indexPath.row ) {
        cell.imageIcon.image = [UIImage imageNamed:[NSString stringWithFormat:@"贫困_%@",self.arrayName[indexPath.row]]];
        cell.labelTitle.text = [NSString stringWithFormat:@"%@",self.arrayName[indexPath.row]];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头，距离右边有十几像素；
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            LSZBasicInformatioShowViewController * vc = [[LSZBasicInformatioShowViewController alloc]init];
            vc.inquiryPoorHouseholdsMg = self.inquiryPoorHouseholdsMg;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            LSZMembersFamilyViewController * vc = [[LSZMembersFamilyViewController alloc]init];
            vc.householdNumber = self.inquiryPoorHouseholdsMg.householdNumber;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            LSZSupportMeasuresViewController * vc = [[LSZSupportMeasuresViewController alloc]init];
            vc.householdNumber = self.inquiryPoorHouseholdsMg.householdNumber;
            vc.inquiryPoorHouseholdsMg = self.inquiryPoorHouseholdsMg;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            LSZHelpLogListViewController * vc = [[LSZHelpLogListViewController alloc]init];
            vc.householdId = self.inquiryPoorHouseholdsMg.id_id;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            LSZHelpResponsiblePersonVC * vc = [[LSZHelpResponsiblePersonVC alloc]init];
            vc.householdNumber = self.inquiryPoorHouseholdsMg.customerId;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}
-(UITableView *)tableViewInformationPoorHouseholds
{
    if (_tableViewInformationPoorHouseholds == nil) {
        _tableViewInformationPoorHouseholds = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height) style:UITableViewStyleGrouped];
        _tableViewInformationPoorHouseholds.delegate = self;
        _tableViewInformationPoorHouseholds.dataSource = self;
        _tableViewInformationPoorHouseholds.estimatedRowHeight=0;
        _tableViewInformationPoorHouseholds.estimatedSectionFooterHeight =0;
        _tableViewInformationPoorHouseholds.estimatedSectionHeaderHeight =0;
        [_tableViewInformationPoorHouseholds setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewInformationPoorHouseholds];
    }
    return _tableViewInformationPoorHouseholds;
}

@end
